<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<input type="text" id="timer">

<button id="start">开始</button>
<button id="end">结束</button>








</body>

<script>
    var a;
    // 获取当前时间,并赋值到input标签中
    function f1() {
        var d = new Date();
        var dStr = d.toLocaleString();

        var inp = document.getElementById('timer');
        inp.value = dStr;
    }

    var startBtn = document.getElementById('start');
    startBtn.onclick = function () {
        f1();
        if (a === undefined){
            a = setInterval(f1,1000); //开启定时器,重复执行f1函数 a=111
        }

    };

    // 点击结束按钮,清除定时器
    var endBtn = document.getElementById('end');

    endBtn.onclick = function () {
        clearInterval(a);
        a = undefined;
    }

</script>

<!--<script src="jquery.js"></script>-->


</html>